package me.ivps.android.weibo.ui.interfaces;

import android.os.Bundle;

/**
 * 抽象 Fragment 基类
 * 
 * User: qii Date: 12-12-30
 */
public class AbstractAppFragment extends FixedOnActivityResultBugFragment {
    /**
     * when activity is recycled by system, isFirstTimeStartFlag will be reset
     * to default true, when activity is recreated because a configuration
     * change for example screen rotate, isFirstTimeStartFlag will stay false
     */
    /**
     * 当 Activity 被回收创建时，此值将被重置为 true; 而当 Activity 由于配置改变重建时，此值将保留为 false.
     */
    private boolean isFirstTimeStartFlag = true;
    
    /**
     * Activity 第一次启动
     */
    protected static final int FIRST_TIME_START = 0;
    /**
     * Activity 屏幕转动导致重建
     */
    protected static final int SCREEN_ROTATE = 1;
    /**
     * Activity 由于内存或其他系统原因导致重建
     */
    protected static final int ACTIVITY_DESTROY_AND_CREATE = 2;
    
    protected int getCurrentState(Bundle savedInstanceState) {
        if (savedInstanceState != null) {
            isFirstTimeStartFlag = false;
            return ACTIVITY_DESTROY_AND_CREATE;
        }
        
        if (!isFirstTimeStartFlag) {
            return SCREEN_ROTATE;
        }
        
        isFirstTimeStartFlag = false;
        return FIRST_TIME_START;
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(false);
    }
}
